#!/usr/bin/env node


//Initializing the requirejs approach to module loading instead of the default CommonJS module approach.
//This is needed to be compatible with the AMD format and allow code to be used on both client and server side.
var requirejs = require('requirejs');
requirejs.config({
    //Pass the top-level main.js/index.js require
    //function to requirejs so that node modules
    //are loaded relative to the top-level JS file.
    nodeRequire: require
});

requirejs(['../dspConverter.js', '../../RDFS/schema.js'], function (dsp, rdfs) {
	
	//A stub RForms-template that will be fleshed out by the converter.
	var stub = {
			"cachedChoices": {
				"http://dublincore.org/2010/10/11/dcterms.rdf": [{
					constraints: {"http://www.w3.org/2000/01/rdf-schema#subPropertyOf": "http://purl.org/dc/terms/contributor"},
					choices: [
						{"value": "http://purl.org/dc/terms/contributor", "label": {"sv": "Medarbetare", "en":"Contributor"}}
					]
				}]
			}
	};
	var prefs =	 {
		"http://voa3r.eu/terms/publicationStatus": {pref: 1},
		"http://voa3r.eu/terms/reviewStatus": {pref: 1},
		"http://purl.org/dc/terms/license": {pref: 1},
		"http://purl.org/dc/terms/accessRights": {pref: 1},
		"http://purl.org/dc/terms/rights": {pref: 1},
		"http://purl.org/dc/terms/bibliographicCitation": {pref: 1, "cls": ["rformsmultiline"]},
		"http://purl.org/dc/terms/description": {pref: 1, "cls": ["rformsmultiline"]},
		"http://purl.org/dc/terms/abstract": {"cls": ["rformsmultiline"]},
		"http://purl.org/dc/terms/subject": {pref: 1},
		"http://www.europeana.eu/schemas/ese/isShownBy": {pref: 1},
		"http://www.europeana.eu/schemas/ese/isShownAt": {pref: 1},
		"http://purl.org/dc/terms/format": {pref: 1},
		"http://purl.org/dc/terms/identifier": {pref: 1},
		"http://purl.org/dc/terms/publisher": {pref: 1},
		"http://purl.org/dc/terms/contributor": {pref: 1},
		"http://purl.org/dc/terms/creator": {pref: 1},
		"http://voa3r.eu/terms/hasMetametadata": {pref: 1}
	};
	
	
	//First load the dcterms and foaf schemas into a single aggregated schema, rdfjson formats are used.
	rdfs.load(["dcterms-schema.rdfjson", "foaf-schema.rdfjson"], function(schema) {
	
		//Call the converter, specifying the infile being a DSP file, the outfile where the stuff should be stored,
		//the schema where titles and descriptions will be looked up and finnaly the stub RForms-template to flesh out.
		dsp.convert({
				infile: "VOA3R.dsp",
				outfile: "VOA3R.json",
				schema: schema,
				stub: stub,
				prefs: prefs
			});
	});
});

